/**
 * 
 */
package com.wrsr.examsys.student.service.impl;

import java.util.List;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import org.springframework.stereotype.Service;

import com.wrsr.examsys.base.dao.BaseDao;
import com.wrsr.examsys.base.service.impl.BaseServiceImpl;
import com.wrsr.examsys.domain.Student;
import com.wrsr.examsys.student.service.StudentService;
import com.wrsr.examsys.valited.StringIsValitedUtils;

/**
 * @author <a href="mailto:2397431783@qq.com">wangruishun</a>
 * @version examsy1.0 2014年12月26日 下午5:21:20
 */
@Service("studentService")
public class StudentServiceImpl extends BaseServiceImpl<Student> implements
		StudentService {
	@Resource
	private StudentService studentService;

	@Override
	public boolean emailIsValited(String email) {
		return StringIsValitedUtils.emailIsValited(email);
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * com.wrsr.examsys.student.service.StudentService#codeIsRight(java.lang
	 * .String)
	 */
	@Override
	public boolean codeIsRight(String code, HttpServletRequest request) {
		String cod = (String) request.getSession().getAttribute("authCode");
		if (cod.equals(code)) {
			return true;
		} else
			return false;
	}

	/*
	 * if email is exist return true
	 * 
	 * @see
	 * com.wrsr.examsys.student.service.StudentService#emailIsExist(java.lang
	 * .String)
	 */
	@Override
	public boolean emailIsExist(String email) {
		String hql = "from Student s where s.email=?";
		List<Student> lists = studentService.findEntityByHQL(hql, email);
		if (lists.size() == 0) {
			return false;
		} else {
			return true;
		}

	}

	@SuppressWarnings("rawtypes")
	@Resource(name = "studentDao")
	public void setDao(BaseDao dao) {
		super.setDao(dao);
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * com.wrsr.examsys.student.service.StudentService#getStudentByEmailAndPwd
	 * (com.wrsr.examsys.domain.Student)
	 */
	@Override
	public boolean getStudentByEmailAndPwd(Student student) {
		String hql = "from Student where email=? and pwd=?";
		List<Student> lists = studentService.findEntityByHQL(hql,
				student.getEmail(), student.getPwd());
		if (lists.size() == 0) {
			return false;
		} else {
			return true;
		}
	}

}
